const db = wx.cloud.database()


// var markerId = markers[i].id
Page({
  
  data: {
    "hasload":"",
    "markertitle":"",
    "leixing": "",
    "shijian": "",
    "didian": "",
    "danwei": "",
    "zhiyaun1": [],
    "zhiyuan": [],
    "shetuan": [],
    "jiangzuo": [],
    "ziyou": [],
    "justforlx":[],


    "weather": {
      "icon": "100",
    },
    "bottom": [{
      "id": 0,
      "text": "首页",
      "selectIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.0.png?sign=8efcdca8770c182531fd1d0a5b98bee7&t=1621066787",
      "selectedIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.1.png?sign=4b58233a9a18aed2b79064b59005387e&t=1621066799",
    }, {
      "id": 1,
      "text": "活动",
      "selectIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.0.png?sign=012969fbfc15e20d6ae5c4a6c9d67f5a&t=1621066822",
      "selectedIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.1.png?sign=837e43574ead133a890d0afe82a79415&t=1621066837",
    }, {
      "id": 2,
      "text": "收藏",
      "selectIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/8.0.0.png?sign=8a80489dff605f44d9507571a1512f7d&t=1621066859",
      "selectedIcon": "",
    }, {
      "id": 3,
      "text": "我的",
      "selectIcon": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/9.0.1.png?sign=ded7f69596df7b109d7bc7516da3ac2c&t=1621066877",
      "selectedIcon": "",
    }],
    "swiper": [{
      "id": 0,
      "image": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.1.png?sign=039adb1580b504cae17dd969e126dbfc&t=1621066705",
      "text": "志愿"
    }, {
      "id": 1,
      "image": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/8.1.png?sign=68db2b5d9d23856f2d98714705236415&t=1621066721",
      "text": "社团"
    }, {
      "id": 2,
      "image": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/9.1.png?sign=9bf516f7732c3451d4947a32187cb144&t=1621066737",
      "text": "讲座"
    }, {
      "id": 3,
      "image": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.1.png?sign=d25f2911799ced25c8fbbf5d73ad983b&t=1621066684",
      "text": "自由"
    }],
    "controls": [{
      "id": 1,
      "iconPath": '/123/yoyo3.png',
      "position": {
        "left": 10,
        "top": 375 - 1,
        "width": 50,
        "height": 50
      },
      "clickable": true
    }],
    "controls2": [{
      id: 2,
      iconPath: '/123/yoyo.png',
      position: {
        left: 50,
        top: 350 - 1,
        width: 50,
        height: 50
      },
      clickable: true
    }],
    "covers": [{
      id: 2,
      latitude: 23.647100,
      longitude: 113.505116,
      iconPath: '/image/location.png'
    }, {
      latitude: 23.653256,
      longitude: 113.686116,
      iconPath: '/image/location.png'
    }],
    "markers": [],
    showView1: true,
    showView2: true,
    latitude: 23.632155,
    longitude: 113.679474,
    scale: 16,
    isShow: false,
    showView: true,
    showView2: true,
    "ziyoumarkers": [],
    "zhiyuanmarkers": [],
    "shetuanmarkers": [],
    "jiangzuomarkers": []
  },

  actioncnt: function () {
    wx.showActionSheet({
      itemList: ['东区游览线路', '西区游览线路', '一日游游览线路1', '快速游览线路2', ],

    })
  },

  onShareAppMessage() {
    return {
      title: 'cover-view',
      path: 'page/component/pages/cover-view/cover-view'
    }
  },

  bindMakertap: function (event) {
    console.log(event, '11111');
    console.log(event.detail.markerId, '11111');
    console.log(event.currentTarget.dataset.id[event.detail.markerId - 1].detail.time, '2222');
    getApp().globalData.carditem_data = event.currentTarget.dataset.id[event.detail.markerId - 1]
    this.setData({
      isShow: true,
      markertitle: event.currentTarget.dataset.id[event.detail.markerId - 1].callout.content,
      leixing: event.currentTarget.dataset.id[event.detail.markerId - 1].Category,
      shijian: event.currentTarget.dataset.id[event.detail.markerId - 1].detail.time,
      didian: event.currentTarget.dataset.id[event.detail.markerId - 1].detail.address,
      danwei: event.currentTarget.dataset.id[event.detail.markerId - 1].detail.sponsor

    })
  },

  bindtap: function (event) {
    // console.log(event, '11111');
    this.setData({
      isShow: false,
    })
  },

  navigatorpage: function (e) {
    console.log(e, '11111');

    wx.navigateTo({
      url: '../../pages/activity/activity'
    })

  },

  bindCommentInput: function (event) {
    var value = event.detail.value;
    return value.replace(/qq/g, "*")
  },

  getCenterLocation: function () {
    this.mapCtx.getCenterLocation({
      success: function (res) {
        console.log(res.longitude)
        console.log(res.latitude)
      }
    })
  },

  moveToLocation: function () {
    this.mapCtx.moveToLocation()
  },

  calling: function (e) {
    // console.log(e.currentTarget.dataset.adata);
    if ("自由" === e.currentTarget.dataset.adata) {
      var that = this;
      // that.setData({
      //   markers: that.data.ziyou,
        
      // })
      that.input4()
      //  获取数据库中的标点坐标
    } else if ("志愿" === e.currentTarget.dataset.adata) {
      var that = this;
      // that.setData({
      //   zhiyaun1: that.data.zhiyuan
      // })
     
     that.input1()
     

      //  获取数据库中的标点坐标





    } else if ("社团" === e.currentTarget.dataset.adata) {
      var that = this;
      // that.setData({
      //   markers: that.data.shetuan
      // })
      that.input2()
      //  获取数据库中的标点坐标

    } else if ("讲座" === e.currentTarget.dataset.adata) {
      var that = this;
      // that.setData({
      //   markers: that.data.jiangzuo
      // })
      that.input3()

      //  获取数据库中的标点坐标

    }
  },

  input1: function (m, index) {
   
    const {zhiyuan} =this.data
    console.log("之前",this.data.zhiyuan)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    zhiyuan.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      zhiyuan.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: zhiyuan
      })
      console.log("之后",this.data.zhiyuan)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },

  input5: function (m, index) {
   
    const {zhiyuan} =this.data
    console.log("之前",this.data.zhiyuan)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    zhiyuan.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        },
        


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      zhiyuan.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: zhiyuan
      })
      console.log("之后",this.data.zhiyuan)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },


  input2: function (m, index) {
   
    const {shetuan} =this.data
    console.log("之前",this.data.zhiyuan)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    shetuan.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      shetuan.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: shetuan
      })
      console.log("之后",this.data.shetuan)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },

  input3: function (m, index) {
   
    const {jiangzuo} =this.data
    console.log("之前",this.data.jiangzuo)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    jiangzuo.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      jiangzuo.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: jiangzuo
      })
      console.log("之后",this.data.jiangzuo)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },

  input4: function (m, index) {
   
    const {ziyou} =this.data
    console.log("之前",this.data.ziyou)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    ziyou.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      ziyou.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: ziyou
      })
      console.log("之后",this.data.ziyou)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },

  tianjiadian: function (e) {
    // console.log(e.currentTarget.dataset.adata);

    wx.navigateTo({
      url: '../../pages/end4/end4'
    })


  },

 

  qusousuo: function (e) {
    // console.log(e.currentTarget.dataset.adata);

    wx.navigateTo({
      url: '../../pages/index2/index2'
    })


  },

  showModal: function (event) {
    //console.log(event.markerId);
    var i = event.markerId;
    var url = app.url + 'Api/Api/get_shop_dp_detail&PHPSESSID=' + wx.getStorageSync('PHPSESSID');
    var that = this;
    // console.log('====get_detail====')
    wx.request({
      url: url,
      data: {
        id: i,
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res);
        that.setData({
          myall: res.data.data
        });
      }
    });



    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },

  weatherChange: function (e) {
    var that = this;
    // console.log("坐标", that.data.geo_location)

   
    wx.request({
      url: 'https://devapi.qweather.com/v7/weather/now?',
      data: {
        key: '96263f15f3d64d8fa861ba6c79cc4f6b',
        location: "113.676278,23.631624",
      },
      success: function (res) {
        // console.log(res.data)
        // console.log("坐标0341", res)
        that.setData({
          weather: res.data.now,
         
          markers:[...that.data.markers,...that.data.justforlx],
        })
      }
    })
  },

  onChangeShowState1: function () {
    var that = this;
    that.setData({
      showView1: (!that.data.showView1)
    })
  },

  onChangeShowState2: function () {
    var that = this;
    that.setData({
      showView2: (!that.data.showView2)
    })
  },

  bottomJump: function (e) {
    // console.log(e.currentTarget.dataset.bottomitemdata)
    if ("首页" === e.currentTarget.dataset.bottomitemdata) {
      wx.redirectTo({
        url: '../../pages/end/end'
      })

    } else if ("活动" === e.currentTarget.dataset.bottomitemdata) {
      wx.redirectTo({
        url: '../../pages/end1/end1'
      })
    } else if ("收藏" === e.currentTarget.dataset.bottomitemdata) {
      wx.redirectTo({
        url: '../../pages/end2/end2'
      })
    } else if ("我的" === e.currentTarget.dataset.bottomitemdata) {
      wx.redirectTo({
        url: '../../pages/end3/end3'
      })
    }
  },

  setPlain: function (e) {
    this.setData({
      plain: !this.data.plain
    })
  },

  onChangeAddress: function () {
    wx.navigateTo({
      url: '../../pages/search/search'
    })
  },

  onReady: function (e) {
    this.mapCtx = wx.createMapContext('myMap')
  },

  includePoints: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.636760,
        longitude: 113.674000
      }, {
        latitude: 23.629780,
        longitude: 113.685040,
      }]
    })
  },
  includePoints1: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.633700,
        longitude: 113.679740,
      }, {
        latitude: 23.631700,
        longitude: 113.677740,
      }]
    })
  },
  includePoints2: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.631780,
        longitude: 113.680650,
      }, {
        latitude: 23.629780,
        longitude: 113.678650,
      }]
    })
  },
  includePoints3: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.635700,
        longitude: 113.680340,
      }, {
        latitude: 23.633700,
        longitude: 113.678340,
      }]
    })
  },
  includePoints4: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.632000,
        longitude: 113.678450,
      }, {
        latitude: 23.630000,
        longitude: 113.676450,
      }]
    })
  },
  includePoints5: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.633900,
        longitude: 113.681140,
      }, {
        latitude: 23.631900,
        longitude: 113.679140,
      }]
    })
  },

  onLoad: function (options) {
    // 生命周期函数--监听页面加载

    var that = this
    this.weatherChange();
    showView1: (options.showView1 == "true" ? true : false);
    showView2: (options.showView2 == "true" ? true : false);

    db.collection("open").get().then(res=>{
      console.log("ojbk",res.data[0].hasload)

   
      this.setData({
        
        "hasload":res.data[0].hasload
      })
    })
  },
  onShow: function () {
    var that = this
    db.collection('all').get().then(res => {
      console.log("asds", res)
      var all_data = [];
      for (let i = 0; i < res.data.length; i++) {
        console.log("空", res.data)
        all_data.push(res.data[i])
      }
      console.log("ds", all_data)
      that.setData({
        markers: all_data,
        justforlx: getApp().globalData.justforlx,
      })

      var zhiyuan = [];
      var shetuan = [];
      var jiangzuo = [];
      var ziyou = [];
      for (let i = 0; i < res.data.length; i++) {
        console.log("空", res.data[i])
        if (res.data[i].mid == 0) {
          zhiyuan.push(res.data[i])
        };
        if (res.data[i].mid == 1) {
          shetuan.push(res.data[i])
        };
        if (res.data[i].mid == 2) {
          jiangzuo.push(res.data[i])
        };
        if (res.data[i].mid == 3) {
          ziyou.push(res.data[i])
        }
      }
      that.setData({
        zhiyuan,
        shetuan,
        jiangzuo,
        ziyou,
      })
    })

  },
})